package org.example.vueesaytest.controller;

import org.example.vueesaytest.POJO.Article;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@CrossOrigin(maxAge = 3600)
@RequestMapping("/article")
public class ArtController {
    private List<Article> articles = new ArrayList<Article>();

    {
        articles.add(new Article("政治和四hi和","新闻","22222","发布"));
        articles.add(new Article("我日他个","世界","11111","草稿"));
    }

    //新增文章
    @PostMapping("/add")
    public String addArticle(@RequestBody Article article) {

        articles.add(article);
        return "新增成功";
    }

    //获取所有文章
    @GetMapping("/getAll")
    public List<Article> getAll() {
        return articles;
    }

    @GetMapping("/search")
    public List<Article> search(@RequestParam String category, @RequestParam String state) {
        return articles.stream()
                .filter(a -> a.getCategory().equals(category) && a.getState().equals(state))
                .collect(Collectors.toList());
    }




}
